<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">
    <title></title>
    <link rel="stylesheet" href="css/weui.css"/>
    <link rel="stylesheet" href="css/merchant_create.css"/>
</head>
<body ontouchstart>
    <div class="weui-toptips weui-toptips_warn js_tooltips">错误提示</div>
·
    <div class="container" id="container"></div>
    <script type="text/html" id="tpl_merchant_create">
<div class="page">
    <div class="page__hd">
        <h1 class="page__title">酒店注册</h1>
    </div>
    <form onsubmit="return false" id="form">
        <div class="page__bd">
            <div class="weui-cells__title">酒店信息</div>
            <div class="weui-cells">
                <div class="weui-cell">
                    <div class="weui-cell__hd"><label class="weui-label">酒店名称</label></div>
                    <div class="weui-cell__bd">
                        <input class="weui-input" type="text" id="name" required placeholder="请输入酒店名称" />
                    </div>
                </div>
                <div class="weui-cell">
                    <div class="weui-cell__hd"><label class="weui-label">地址</label></div>
                    <div class="weui-cell__bd">
                        <p class="weui-input" id="regionClick"><span id="regionText">省&nbsp;/&nbsp;市&nbsp;/&nbsp;区</span></p><input id="region" type="hidden" required placeholder="请选择省/市/区" />
                    </div>
                </div>
                <div class="weui-cell">
                    <div class="weui-cell__bd">
                        <textarea class="weui-textarea" required id="address" placeholder="请输入详细地址" rows="3"></textarea>
                        <!-- <div class="weui-textarea-counter"><span>0</span>/200</div> -->
                    </div>
                </div>
            </div>
            <!-- <div class="weui-cells__title">管理者信息</div>
            <div class="weui-cells">
                <div class="weui-cell">
                    <div class="weui-cell__hd"><label class="weui-label">管理者微信</label></div>
                    <div class="weui-cell__bd">
                        <p class="weui-input">坏蛋仔仔</p>
                    </div>
                </div>
                <div class="weui-cell weui-cell_select weui-cell_select-before weui-cell_vcode">
                    <div class="weui-cell__hd">
                        <select class="weui-select" name="select2">
                            <option value="1">+86</option>
                            <option value="2">+80</option>
                            <option value="3">+84</option>
                            <option value="4">+87</option>
                        </select>
                    </div>
                    <div class="weui-cell__bd">
                        <input class="weui-input" type="number" pattern="[0-9]*" placeholder="请输入号码"/>
                    </div>
                    <div class="weui-cell__ft">
                        <button class="weui-vcode-btn">获取验证码</button>
                    </div>
                </div>
                <div class="weui-cell">
                    <div class="weui-cell__hd"><label class="weui-label">验证码</label></div>
                    <div class="weui-cell__bd">
                        <input class="weui-input" type="number" pattern="[0-9]*" placeholder="请输入验证码">
                    </div>
                </div>
            </div>
            <label for="weuiAgree" class="weui-agree">
                <input id="weuiAgree" type="checkbox" class="weui-agree__checkbox"/>
                <span class="weui-agree__text">
                    阅读并同意<a href="javascript:void(0);">《相关条款》</a>
                </span>
            </label> -->

            <div class="weui-btn-area">
                <a class="weui-btn weui-btn_primary" href="javascript:" id="formSubmitBtn">提交</a>
            </div>
        </div>
    </form>
    <div class="page__ft">
        <a href="javascript:home()"><img src="./images/icon_footer_link.png" /></a>
    </div>
</div>
<script type="text/javascript">
    $(function(){
        var $tooltips = $('.js_tooltips');
        $('title').html("酒店注册");
        var regexp = {
            regexp: {
                IDNUM: /(?:^\d{15}$)|(?:^\d{18}$)|^\d{17}[\dXx]$/,
                VCODE: /^.{4}$/
            }
        };
        document.querySelector('#formSubmitBtn').addEventListener('click', function () {
            weui.form.validate('#form', function (error) {
                if(error){
                    window.setTimeout(function(){
                        error.ele.parentNode.parentNode.className = "weui-cell";
                    },3000);
                }else{
                    var loading = weui.loading('提交中...',{
                        className: "loading"
                    });
                    // setTimeout(function () {
                    //     loading.hide();
                    //     setTimeout(function(){
                    //         weui.toast('提交成功',{
                    //             duration: 1000,
                    //             className: "loading"
                    //         });
                    //     }, 150);
                    // }, 1500);

                    $.ajax({
                        url : "/open/merchant_create",
                        type : "post",
                        data : {
                            name : $('#name').val(),
                            area : $('#region').val(),
                            address : $('#address').val(),
                            token : token
                        },
                        dataType : "json",
                        success : function(data){
                            var url = window.location.href.split("#")[0];
                            url += '#msg_success';
                            msg = "注册成功";
                            window.location.href = url;
                            loading.hide();
                        },
                        error : function(err){
                            msg = "服务器链接失败，请联系管理员";
                            var url = window.location.href.split("#")[0];
                            url += '#msg_warn';
                            window.location.href = url;
                            loading.hide();
                        }
                    });
                }
            },regexp);
        });

        $.getJSON("/open/getRegion", function(res){
            if(!res.code)
                document.querySelector('#regionClick').addEventListener('click', function () {
                    var region = res.docs;
                    weui.picker(region, {
            	        depth: 3,
                        className: 'custom-classname',
            	        defaultValue: [0, 0, 0],
            	        onConfirm: function onConfirm(result) {
                            var p = {
                                label : region[result[0]].label,
                                data : region[result[0]]
                            };
                            var c = {
                                label : p.data.children[result[1]].label,
                                data : p.data.children[result[1]]
                            };
                            var a = {
                                label : c.data.children[result[2]].label
                            }
                            document.querySelector('#regionText').innerHTML = p.label + "&nbsp;/&nbsp;"+ c.label + "&nbsp;/&nbsp;" + a.label;

                            document.querySelector('#region').value = result.join(',');

            	        },
            	        id: 'cascadePicker'
            	    });
                });
            else
                alert(res.msg);
        });

    });
</script>

</script>
    <script type="text/html" id="tpl_msg_warn">
<div class="page">
    <div class="weui-msg">
        <div class="weui-msg__icon-area"><i class="weui-icon-warn weui-icon_msg"></i></div>
        <div class="weui-msg__text-area">
            <h2 class="weui-msg__title">操作失败</h2>
            <p class="weui-msg__desc" id="err_text"></p>
        </div>
        <div class="weui-msg__opr-area">
            <p class="weui-btn-area">
                <a id="reScanQRCode" href="javascript:void(0);" class="weui-btn weui-btn_primary">重新扫描</a>
                <a id="closeWindow" href="javascript:void(0);" class="weui-btn weui-btn_default">关闭页面</a>
            </p>
        </div>
        <div class="weui-msg__extra-area">
            <div class="weui-footer">
                <p class="weui-footer__links">
                    <a href="javascript:void(0);" class="weui-footer__link">底部链接文本</a>
                </p>
                <p class="weui-footer__text">Copyright &copy; 2008-2016 weui.io</p>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">

    if(msg){
        $('title').html(msg);
        $('#err_text').html(msg);
    }

    wx.ready(function(){
        $("#closeWindow").click(function(){
            wx.closeWindow();
        });
        $("#reScanQRCode").click(function(){
            wx.scanQRCode({
                success: function(res){
                    wx.closeWindow();
                }
            });
        });
    });
</script>

</script>
    <script type="text/html" id="tpl_msg_success">
<div class="page">
    <div class="weui-msg">
        <div class="weui-msg__icon-area"><i class="weui-icon-success weui-icon_msg"></i></div>
        <div class="weui-msg__text-area">
            <h2 class="weui-msg__title" id="success"></h2>
        </div>
        <div class="weui-msg__opr-area">
            <p class="weui-btn-area">
                <a href="javascript:void(0);" id="success_close" class="weui-btn weui-btn_primary">关闭</a>
            </p>
        </div>
        <div class="weui-msg__extra-area">
            <div class="weui-footer">
                <p class="weui-footer__links">
                    <a href="javascript:void(0);" class="weui-footer__link">底部链接文本</a>
                </p>
                <p class="weui-footer__text">Copyright &copy; 2008-2016 weui.io</p>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $("title").html("注册成功");
    $('#success').html(msg);
    wx.ready(function(){
        $("#success_close").on('click', function(){
            wx.closeWindow();
        });
    });
</script>

</script>

    <script src="js/zepto.min.js"></script>
    <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script src="https://res.wx.qq.com/open/libs/weuijs/1.0.0/weui.min.js"></script>
    <script type="text/javascript">
    var msg = "<%= msg || 0 %>";
    var jssdk = <%- JSON.stringify(docs.jssdk) %>;
    var token = "<%= docs.token || 0 %>";
    jssdk.jsApiList = ["closeWindow", "scanQRCode"];
    wx.config(jssdk);
    </script>
    <script src="js/merchant_create.js"></script>
</body>
</html>
